package com.kob.backend.service.impl.user.account;

import com.kob.backend.pojo.user;
import com.kob.backend.service.impl.utils.UserDetailsImpl;
import com.kob.backend.service.user.account.InfoService;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class InfoServiceImpl implements InfoService {

    @Override
    public Map<String, String> getinfo() {
        UsernamePasswordAuthenticationToken authenticationToken=
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl loginUser=(UserDetailsImpl) authenticationToken.getPrincipal();
        user this_user= loginUser.getThis_user();
        Map<String,String>map=new HashMap<>();
        map.put("error_message","success");
        map.put("id",this_user.getId().toString());
        map.put("username", this_user.getUsername());
        map.put("email", this_user.getEmail());
        map.put("phone", this_user.getPhone());
        map.put("address",this_user.getAddress());
        return map;

    }
}
